Skip to content

fix(runtime): stop failover and keep the transport error when shouldRetry fails - #12

Merged
erwinmsmith merged 1 commit into
CodeSoul-co:devfrom
Tim0085:fix/should-retry-errors
Dec 1, 2026
Merged

erwinmsmith merged 1 commit into
CodeSoul-co:devfrom
Tim0085:fix/should-retry-errors

Conversation

@Tim0085

@Tim0085 Tim0085 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Problem

recoveryPolicy.shouldRetry is awaited inside the attempt's catch block with no error handling of its own (src/runtime/runtime.ts). If the callback throws or rejects (for example, because the receipt lookup it awaits fails), two things go wrong:

  • The caller receives the callback's error instead of the TransportError. That drops code and status, which tell the caller whether the operation may already have run.
  • recovery.decided is never emitted. The events end at attempt.failed, although the docs say "recovery.decided records the choice".

A receipt store being briefly unavailable is exactly the situation shouldRetry exists for, so this path is likely in practice.

Change

  • A throwing or rejecting shouldRetry now counts as "do not retry". The Runtime emits recovery.decided with decision: "stop" and rethrows the original TransportError. The reasoning: a safety check that could not finish has not shown that replay is safe.
  • Cancellation behaves as before. If the signal aborts while the callback runs, the abort reason still wins.
  • Updated the RecoveryPolicy doc comment and the failover paragraph in docs/worker-communication.md and .zh-CN.md.
  • New test in test/runtime-failover.test.ts, covering both a synchronous throw and a rejected promise. It checks the rejected error is the original TIMEOUT / outcome_unknown TransportError for the first attempt, that there is no second dispatch, and that the events end with recovery.decided / stop.

Open question

The callback's own error is not passed on: the application can log it inside its callback, as with onExecutionEvent observers. If you'd rather surface it, I can attach it to the recovery.decided event or wrap both errors. I kept TransportError as the thrown type so instanceof and status checks keep working.

Validation

Run with npm run check on Windows 11, Node 24.14.0, on top of dev at f0e5297:

  • Typecheck and builds pass. Tests: 518 total, 511 passed, 3 skipped, 4 failed.
  • The new test passes. With only the runtime.ts change reverted, it fails: the caller gets Error: receipt store unavailable.
  • The 4 failures are the same Windows-only ones reported in fix(examples): derive SQL memory IDs from keys so search results are reproducible #10 (symlink EPERM ×2, the sandbox environment-key assertion, and the capability-boundary audit). They also fail on unmodified dev, and none touches the files changed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants